/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package user_interface;

import DataAccessObject.tblThanhVienDAO;
import EntityObject.tblThanhVienEO;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author minh
 */
public class KetXuat_UI extends javax.swing.JFrame {
public tblThanhVienEO _tblThanhVienEO = new tblThanhVienEO(0, null, null, false,null, null, null, null, null, null, null, 0 , null, null);
public int tuoi;
    /**
     * Creates new form KetXuat_UI
     */
    public KetXuat_UI() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jLabel1 = new javax.swing.JLabel();
        rbtnTatCa = new javax.swing.JRadioButton();
        rbtnTen = new javax.swing.JRadioButton();
        rbtnDoi = new javax.swing.JRadioButton();
        rbtnGioiTinh = new javax.swing.JRadioButton();
        txtValue = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        rbtnTuoi = new javax.swing.JRadioButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tbketxuat = new javax.swing.JTable();
        btnThoat = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Times New Roman", 1, 32)); // NOI18N
        jLabel1.setText("KẾT XUẤT CÂY PHẢ HỆ DÒNG HỌ");

        buttonGroup1.add(rbtnTatCa);
        rbtnTatCa.setText("Tất cả");
        rbtnTatCa.setToolTipText("");
        rbtnTatCa.setActionCommand("");
        rbtnTatCa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbtnTatCaActionPerformed(evt);
            }
        });

        buttonGroup1.add(rbtnTen);
        rbtnTen.setText("Tìm theo tên TV");
        rbtnTen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbtnTenActionPerformed(evt);
            }
        });

        buttonGroup1.add(rbtnDoi);
        rbtnDoi.setText("Tìm theo đời");
        rbtnDoi.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbtnDoiActionPerformed(evt);
            }
        });

        buttonGroup1.add(rbtnGioiTinh);
        rbtnGioiTinh.setText("Tìm theo giới tính");
        rbtnGioiTinh.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbtnGioiTinhActionPerformed(evt);
            }
        });

        txtValue.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtValueActionPerformed(evt);
            }
        });

        jButton1.setText("Tìm");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        buttonGroup1.add(rbtnTuoi);
        rbtnTuoi.setText("Tìm theo tuổi");
        rbtnTuoi.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbtnTuoiActionPerformed(evt);
            }
        });

        tbketxuat.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(tbketxuat);

        btnThoat.setText("Thoát");
        btnThoat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnThoatActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(204, 204, 204)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(txtValue, javax.swing.GroupLayout.PREFERRED_SIZE, 361, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jButton1)
                        .addGap(37, 37, 37)
                        .addComponent(btnThoat))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(rbtnTatCa)
                            .addComponent(rbtnTen)
                            .addComponent(rbtnDoi))
                        .addGap(80, 80, 80)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(rbtnGioiTinh)
                            .addComponent(rbtnTuoi)))
                    .addComponent(jLabel1))
                .addContainerGap(132, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 831, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(19, 19, 19))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(26, 26, 26)
                .addComponent(jLabel1)
                .addGap(30, 30, 30)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rbtnTatCa)
                    .addComponent(rbtnTuoi))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(rbtnGioiTinh)
                        .addGap(10, 10, 10))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(rbtnTen)
                        .addGap(18, 18, 18)))
                .addComponent(rbtnDoi)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtValue, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1)
                    .addComponent(btnThoat))
                .addGap(53, 53, 53)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 232, Short.MAX_VALUE)
                .addContainerGap())
        );

        rbtnTatCa.getAccessibleContext().setAccessibleName("");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txtValueActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtValueActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtValueActionPerformed

    public  void BindDataTable(ResultSet rs) {
        DefaultTableModel tableModel = new DefaultTableModel();
        Vector title = new Vector();
        title.addElement("Mã thành viên");
        title.addElement("Tên thành viên");  
        title.addElement("Tên Bố");
        title.addElement("Tên Mẹ");    
      //  title.addElement("Tên húy");
        title.addElement("Giới tính");
      // title.addElement("Nơi sinh");
        title.addElement("Nơi ở hiện tại");
        title.addElement("Ngày sinh");
        title.addElement("Ngày mất");
        title.addElement("Nơi an táng");
     //   title.addElement("Trình độ văn Hóa");
      //  title.addElement("Nghề nghiệp");
        title.addElement("Đời thứ");
      //  title.addElement("Nhóm máu");
      //  title.addElement("Ghi chú");    
        tableModel.setColumnIdentifiers(title);
        
        
//        _tblThanhVienEO.setPK_iMaTV(0);
//        _tblThanhVienEO.setsTenTV(null);
//        _tblThanhVienEO.setsTenHuy(null);
//        _tblThanhVienEO.setbGioiTinh(null);
//        _tblThanhVienEO.setsNoiSinh(null);
//        _tblThanhVienEO.setsNoiOHienTai(null);
//        _tblThanhVienEO.setsNgaySinh(null);
//        _tblThanhVienEO.setsNgayMat(null);
//        _tblThanhVienEO.setsNoiAnTang(null);
//        _tblThanhVienEO.setsTrinhDoVH(null);
//        _tblThanhVienEO.setsNgheNghiep(null);
//        _tblThanhVienEO.setiDoiThu(0);
//        _tblThanhVienEO.setsNhomMau(null);
//        _tblThanhVienEO.setsGhiChu(null);

        try {
           int sl = 0;
           
           String gt;
            while (rs.next()) {
                Vector data = new Vector();
                data.addElement(rs.getInt(1));  // Mã TV kiểu Int
                data.addElement(rs.getString(2));  // Tên TV kiểu string
                data.addElement(rs.getString(3));  // Tên TV kiểu string
                data.addElement(rs.getString(4));  // Mã TV kiểu String
            //    data.addElement(rs.getString(5));  // Mã TV kiểu String
                if(rs.getBoolean(5) == false){
                gt="nữ";
                }
                else{
                    gt="nam";
                }
                data.addElement(gt);      // Tên TV kiểu Boolean
            //    data.addElement(rs.getString(7));  // Mã TV kiểu String
                data.addElement(rs.getString(6));
                data.addElement(rs.getString(7));
                data.addElement(rs.getString(8));
                data.addElement(rs.getString(9));
            //    data.addElement(rs.getString(12));
            //    data.addElement(rs.getString(13));
                data.addElement(rs.getInt(10));
            //    data.addElement(rs.getString(15));
            //    data.addElement(rs.getString(16));
                tableModel.addRow(data);
                sl=sl+1;
            }
            System.out.println("tong:" +sl);
        } catch (SQLException e) {
            JOptionPane.showMessageDialog(this, "Lỗi Load Dữ liệu tại bảng Thành viên:' "+e.getMessage()+ " '");
        }
        tbketxuat.setModel(tableModel);
    }
    
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        _tblThanhVienEO = new tblThanhVienEO(0, null, null, null,null, null, null, null, null, null, null, 0 , null, null);
        tuoi=0;
        if(rbtnTatCa.isSelected()==true){
            //_tblThanhVienEO.setbGioiTinh(Boolean.parseBoolean(txtValue.getText()));
        }
        if(rbtnTuoi.isSelected()==true){
            tuoi = Integer.parseInt(txtValue.getText());
        }
        if(rbtnTen.isSelected()==true){
            _tblThanhVienEO.setsTenTV(txtValue.getText());
        }
        if(rbtnGioiTinh.isSelected()==true){
            if(txtValue.getText().trim().toLowerCase().equals("nữ")==true){
                _tblThanhVienEO.setbGioiTinh(false);
            }
            else{
            _tblThanhVienEO.setbGioiTinh(true);
            }
        }
        if(rbtnDoi.isSelected()==true){
            _tblThanhVienEO.setiDoiThu(Integer.parseInt(txtValue.getText()));
        }
        try {
            ResultSet rs = tblThanhVienDAO.ThanhVien_SelectList_KetXuat(_tblThanhVienEO,tuoi);
            BindDataTable(rs);
        } catch (SQLException ex) {
            Logger.getLogger(KetXuat_UI.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void rbtnTatCaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbtnTatCaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_rbtnTatCaActionPerformed

    private void rbtnTuoiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbtnTuoiActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_rbtnTuoiActionPerformed

    private void rbtnGioiTinhActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbtnGioiTinhActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_rbtnGioiTinhActionPerformed

    private void rbtnTenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbtnTenActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_rbtnTenActionPerformed

    private void rbtnDoiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbtnDoiActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_rbtnDoiActionPerformed

    private void btnThoatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnThoatActionPerformed
        // TODO add your handling code here:
                this.setVisible(false);
    }//GEN-LAST:event_btnThoatActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(KetXuat_UI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(KetXuat_UI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(KetXuat_UI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(KetXuat_UI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new KetXuat_UI().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnThoat;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JRadioButton rbtnDoi;
    private javax.swing.JRadioButton rbtnGioiTinh;
    private javax.swing.JRadioButton rbtnTatCa;
    private javax.swing.JRadioButton rbtnTen;
    private javax.swing.JRadioButton rbtnTuoi;
    private javax.swing.JTable tbketxuat;
    private javax.swing.JTextField txtValue;
    // End of variables declaration//GEN-END:variables
}
